package T21_30;

public class T27 {
    public static class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        //递归，无需多言
        if (list1==null)return list2;
        if (list2==null)return list1;
        ListNode res=new ListNode();
        if (list1.val<list2.val){
            res.val= list1.val;
            res.next=mergeTwoLists(list1.next,list2);
        }else {
            res.val= list2.val;
            res.next=mergeTwoLists(list1,list2.next);
        }
        return res;
    }
}
